<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="div1"><p>p1</p>
        <p>p2</p>
    </div>
    <button onclick="getFirst()">获取第一个子节点</button>
    <button onclick="getLast()">获取最后一个子节点</button>
    <script>
        let div = document.querySelector(".div1");

        function getFirst() {
            console.log(div.firstChild);
        }

        function getLast() {
            console.log(div.lastChild);
        }
    </script>
</body>
</html>